//
//  PieChartViewController.m
//  MoneyLog
//
//  Created by wicresoft on 6/10/11.
//  Copyright 2011 wicresoft. All rights reserved.
//

#import "PieChartViewController.h"
#import "pieChartView.h"
#import "RecordWrapper.h"
#import "PieChartItem.h"
#import "PieChartTableCellView.h"

extern NSString *kRowViewKey;
extern NSString *kRowItemKey;

@implementation PieChartViewController
@synthesize _tableView;
@synthesize dataSourceArray;
@synthesize controllerState,searchStartDate,searchEndDate,searchString;
@synthesize chartView;
@synthesize dateSelectView;
@synthesize startPickerView,endPickerView;
@synthesize pikcerDataSource;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [_tableView release];
    [dataSourceArray release]; 
    
    [searchStartDate release];
    [searchEndDate release];
    [searchString release];
    
    [chartView release];
    [titleView removeFromSuperview];
    [titleButton release];
    
    [dateSelectView release];
    [startPickerView release];
    [endPickerView release];
    [pikcerDataSource release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
     NSString *titleString =[NSString stringWithFormat:@" %02d/%02d/%02d-%02d/%02d/%02d",
                             searchStartDate.year%100,
                             searchStartDate.month,
                             searchStartDate.day,
                             searchEndDate.year%100,
                             searchEndDate.month,
                             searchEndDate.day];
    if (controllerState == kPieChartControllerAll) {
        titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];//allocate titleView
        titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [titleButton setFrame:CGRectMake(0, 0, 200, 38)];
        [titleButton addTarget:self action:@selector(titleAction) forControlEvents:UIControlEventTouchUpInside];
        [titleButton setTitle:titleString forState:UIControlStateNormal];
        [titleButton setImage:[UIImage imageNamed:@"group_button_down.png"] forState:UIControlStateNormal];
        titleButton.titleLabel.textColor = [UIColor whiteColor];
        titleButton.backgroundColor =[UIColor clearColor];
        [titleView addSubview:titleButton];
        self.navigationItem.titleView=titleView;
    }
    else {
        self.title = titleString;
    }
       
    self.dataSourceArray = [[NSMutableArray alloc] initWithCapacity:0];
    chartView= [[pieChartView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
    
    CGRect appRect = [[UIScreen mainScreen] applicationFrame];
    dateSelectView.frame = CGRectMake(0, appRect.size.height, appRect.size.width, 250);
    dateSelectView.hidden=YES;
    [self.view addSubview:dateSelectView];
    //[self.view insertSubview:dateSelectView aboveSubview:chartView];
    
    pikcerDataSource = [[NSMutableArray alloc] initWithCapacity:1];
    NSMutableArray *yearArray = [NSMutableArray array];
    for (int i=1; i<=3; i++) {
        [yearArray addObject:[NSString stringWithFormat:@"%d",(2011-3)+i]];
    }
    [pikcerDataSource  addObject:yearArray];
    
    NSMutableArray *monthArray = [NSMutableArray array];
    for (int i=1; i<=12; i++) {
        [monthArray addObject:[NSString stringWithFormat:@"%d",i]];
    }
    [pikcerDataSource addObject:monthArray];
    
    NSMutableArray *dayArray = [NSMutableArray array];
    for (int i=1; i<=31; i++) {
        [dayArray addObject:[NSString stringWithFormat:@"%d",i]];
    }
    [pikcerDataSource addObject:dayArray];
    
    [startPickerView selectRow:[yearArray indexOfObject:[NSString stringWithFormat:@"%d",searchStartDate.year]] inComponent:0 animated:YES];
    [startPickerView selectRow:[monthArray indexOfObject:[NSString stringWithFormat:@"%d",searchStartDate.month]] inComponent:1 animated:YES];
    [startPickerView selectRow:[dayArray indexOfObject:[NSString stringWithFormat:@"%d",searchStartDate.day]] inComponent:2 animated:YES];
    
    [endPickerView selectRow:[yearArray indexOfObject:[NSString stringWithFormat:@"%d",searchEndDate.year]] inComponent:0 animated:YES];
    [endPickerView selectRow:[monthArray indexOfObject:[NSString stringWithFormat:@"%d",searchEndDate.month]] inComponent:1 animated:YES];
    [endPickerView selectRow:[dayArray indexOfObject:[NSString stringWithFormat:@"%d",searchEndDate.day]] inComponent:2 animated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self getPieChartController];
    [self._tableView reloadData];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - * Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40.0;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return nil;
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    NSString *title = nil;
	
	return title;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [self.dataSourceArray count];}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PieChartViewCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
       
    if (self.controllerState == kPieChartControllerIncome || self.controllerState == kPieChartControllerSubExpense ) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    [cell.contentView addSubview:[[self.dataSourceArray objectAtIndex:indexPath.row] objectForKey:kRowViewKey]];
    
    return cell;
}

//// Override to support conditional editing of the table view.
//- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    // Return NO if you do not want the specified item to be editable.
//    return YES;
//}
//
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return UITableViewCellEditingStyleNone;
//}
//
//// Override to support editing the table view.
//- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    if (editingStyle == UITableViewCellEditingStyleDelete) {
//        // Delete the row from the data source
//    }   
//    else if (editingStyle == UITableViewCellEditingStyleInsert) {
//        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
//    }   
//    
//}
//
//- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
//{
//	NSLog(@"section: %d, row: %d", indexPath.section, indexPath.row);
//}
//
//- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
//{
//	NSLog(@"section: %d, row: %d", indexPath.section, indexPath.row);
//}

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

#pragma mark - * Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.controllerState == kPieChartControllerIncome || self.controllerState == kPieChartControllerSubExpense ) {
        return;
    }
    
    UIBarButtonItem *backItem=[[UIBarButtonItem alloc] 
                               initWithTitle:@"返回" 
                               style:UIBarButtonItemStyleBordered 
                               target:nil 
                               action:nil];
    
    PieChartViewController *controller = [[PieChartViewController alloc] init];
    self.navigationItem.backBarButtonItem = backItem;
    PieChartItem *item = [[self.dataSourceArray objectAtIndex:indexPath.row] objectForKey:kRowItemKey];
    controller.searchStartDate =self.searchStartDate;
    controller.searchEndDate = self.searchEndDate;
    
    switch (self.controllerState) {
        case kPieChartControllerAll:
        {
            controller.searchString =[NSString stringWithFormat:@" a.type=\"%@\"",item.title];
            NSLog(@"indexPath.row=%d",indexPath.row);
            if ([item.title isEqualToString:@"收入"]) {
                controller.controllerState = kPieChartControllerIncome;
            }
            else  if([item.title isEqualToString:@"支出"])
            {
                controller.controllerState = kPieChartControllerExpense;
            }
            
            break;
        }
        case kPieChartControllerExpense:
        {
            controller.searchString =[NSString stringWithFormat:@" a.kind=\"%@\"",item.title];
            controller.controllerState = kPieChartControllerSubExpense;
            break;
        }
        default:
            break;
    }
    
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
    
    [backItem release];
    
}

#pragma mark - * UIPickerViewDelegate

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSMutableArray *array= [pikcerDataSource objectAtIndex:component];
	if (pickerView.tag == 100)
	{
        if (component == 0) {
            searchStartDate.year = [[array objectAtIndex:row] intValue];
        }
        else if(component == 1) {
            searchStartDate.month = [[array objectAtIndex:row] intValue];
        }
        else {
            searchStartDate.day = [[array objectAtIndex:row] intValue];
        }
	}
    else if(pickerView.tag ==101) {
        if (component == 0) {
            searchEndDate.year = [[array objectAtIndex:row] intValue];
        }
        else if(component == 1){
            searchEndDate.month = [[array objectAtIndex:row] intValue];
        } 
        else {
             searchEndDate.day = [[array objectAtIndex:row] intValue];
        }
    }
}

#pragma mark - * UIPickerViewDataSource

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	NSString *content=@"";
    
    NSMutableArray *array= [pikcerDataSource objectAtIndex:component];
    content =[array objectAtIndex:row];
    
	return content;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
	CGFloat componentWidth = 40.0;
	
	if (component == 0)
		componentWidth = 60.0;	// first column size is wider to hold names
	else
		componentWidth = 40.0;	// second column is narrower to show numbers
	
	return componentWidth;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
	return 40.0;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    NSMutableArray *array= [pikcerDataSource objectAtIndex:component];
	return [array count]; 
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return 3;
}

#pragma mark - * Actions

-(void) statRecord:(PieChartControllerState) state{  
    NSString *sql = @"select * from record a,record b";
    sql = [sql stringByAppendingFormat:@" where (a.year>=%d and a.month>=%d and a.day>=%d) and (b.year<=%d and b.month<=%d and b.day<=%d) and a.id=b.id ",
           searchStartDate.year,
           searchStartDate.month,
           searchStartDate.day,
           searchEndDate.year,
           searchEndDate.month,
           searchEndDate.day];
    sql = [sql stringByAppendingFormat:@" and %@",self.searchString];
    
    NSMutableArray *arrary = [g_Database getRecordArrayBySql:sql];
    NSMutableArray *resultArray = [NSMutableArray array];
    double         totalMoney;
    
    switch (state) {
        case kPieChartControllerAll:
        {
            NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"type" ascending:NO];
            NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
            [arrary sortUsingDescriptors:sortDescriptors];
            [sortDescriptor release];
            
            for (RecordWrapper *record in arrary) {
                
                NSLog(@"record.type=%@",record.type);
                if ([record.type isEqualToString:@""]) {
                    continue;
                }
                
                if ([resultArray count]==0) {
                    PieChartItem *latestItem=[[PieChartItem alloc] init];
                    latestItem.value = record.money;
                    latestItem.title = record.type;
                    
                    [resultArray addObject:latestItem];
                    [latestItem release];
                }
                else
                {
                    PieChartItem *latestItem =[resultArray objectAtIndex:[resultArray count]-1];
                    if ([latestItem.title isEqualToString:record.type]) {
                        latestItem.value +=record.money;
                    }
                    else {
                        PieChartItem *latestItem=[[PieChartItem alloc] init];
                        latestItem.value = record.money;
                        latestItem.title = record.type;
                        
                        [resultArray addObject:latestItem];
                        [latestItem release];
                    }
                }
                
                totalMoney +=record.money;
            }
            
            for(PieChartItem *item in resultArray) {
                item.percent = item.value/totalMoney;
            }
            
            break;
        }
        case kPieChartControllerExpense:
        case kPieChartControllerIncome:
        {
            NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"kind" ascending:NO];
            NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
            [arrary sortUsingDescriptors:sortDescriptors];
            [sortDescriptor release];
            
            for (RecordWrapper *record in arrary) {
                
                NSLog(@"record.kind=%@",record.kind);
                if ([record.kind isEqualToString:@""]) {
                    continue;
                }
                
                if ([resultArray count]==0) {
                    PieChartItem *latestItem=[[PieChartItem alloc] init];
                    latestItem.value = record.money;
                    latestItem.title = record.kind;
                    
                    [resultArray addObject:latestItem];
                    [latestItem release];
                }
                else
                {
                    PieChartItem *latestItem =[resultArray objectAtIndex:[resultArray count]-1];
                    if ([latestItem.title isEqualToString:record.kind]) {
                        latestItem.value +=record.money;
                    }
                    else {
                        PieChartItem *latestItem=[[PieChartItem alloc] init];
                        latestItem.value = record.money;
                        latestItem.title = record.kind;
                        
                        [resultArray addObject:latestItem];
                        [latestItem release];
                    }
                }
                
                totalMoney +=record.money;
            }
            
            for(PieChartItem *item in resultArray) {
                item.percent = item.value/totalMoney;
            }
    
            break;
        }
        case kPieChartControllerSubExpense:
        {
            NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"subKind" ascending:NO];
            NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
            [arrary sortUsingDescriptors:sortDescriptors];
            [sortDescriptor release];
            
            for (RecordWrapper *record in arrary) {
                
                NSLog(@"record.subKind=%@",record.subKind);
                if ([record.subKind isEqualToString:@""]) {
                    continue;
                }
                
                if ([resultArray count]==0) {
                    PieChartItem *latestItem=[[PieChartItem alloc] init];
                    latestItem.value = record.money;
                    latestItem.title = record.subKind;
                    
                    [resultArray addObject:latestItem];
                    [latestItem release];
                }
                else
                {
                    PieChartItem *latestItem =[resultArray objectAtIndex:[resultArray count]-1];
                    if ([latestItem.title isEqualToString:record.subKind]) {
                        latestItem.value +=record.money;
                    }
                    else {
                        PieChartItem *latestItem=[[PieChartItem alloc] init];
                        latestItem.value = record.money;
                        latestItem.title = record.subKind;
                        
                        [resultArray addObject:latestItem];
                        [latestItem release];
                    }
                }
                
                totalMoney +=record.money;
            }
            
            for(PieChartItem *item in resultArray) {
                item.percent = item.value/totalMoney;
            }
            
            break;
        }
        default:
            break;
    }
    
//    if ([self.dataSourceArray count]==0) {
//        PieChartItem *item =[[PieChartItem alloc] init];
//        item.title =
//    }
    
    NSSortDescriptor *endSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"value" ascending:NO];
    NSArray *endSortDescriptors = [NSArray arrayWithObject:endSortDescriptor];
    [resultArray sortUsingDescriptors:endSortDescriptors];
    [endSortDescriptor release];
    
    CGRect appRect =[[UIScreen mainScreen] applicationFrame];
    [self.dataSourceArray removeAllObjects];
    for (PieChartItem *item in resultArray) {
        [self.dataSourceArray addObject:
         [NSDictionary dictionaryWithObjectsAndKeys:
          item,kRowItemKey,
          [self tableCellView:item frame:CGRectMake(0, 0, appRect.size.width, 40)],kRowViewKey,
          nil]];
    }
}

-(id)tableCellView:(PieChartItem *)item frame:(CGRect)frame 
{
    PieChartTableCellView *cellView = [[[PieChartTableCellView alloc] initWithFrame:frame] autorelease];
    cellView.item =item;
    
    return cellView;
}

-(void)getPieChartController {
    
    [self statRecord:self.controllerState];
    [self.chartView removeFromSuperview];
    
    NSMutableArray *titleArray = [NSMutableArray array];
    NSMutableArray *valueArray = [NSMutableArray array];
    NSMutableArray *colorArray = [NSMutableArray array];
    for (NSDictionary *dictionary in self.dataSourceArray) {
        PieChartItem *item =[dictionary objectForKey:kRowItemKey];
        [titleArray addObject:item.title];
        [valueArray addObject:[NSNumber numberWithInt:item.value]];
    }
    
    NSArray *allColorArray=[NSArray arrayWithObjects:
                         UIColorFromRGB(0x724d9a),UIColorFromRGB(0x48549c),UIColorFromRGB(0x4173ba),UIColorFromRGB(0x47a3ae),
                         UIColorFromRGB(0x0a7d42),UIColorFromRGB(0x639b44),UIColorFromRGB(0xd1c02a),UIColorFromRGB(0xdb9728),
                         UIColorFromRGB(0xc46d2a),UIColorFromRGB(0xed6952),UIColorFromRGB(0xea4043),UIColorFromRGB(0x87266b),nil];
   
    if ([self.dataSourceArray count]<=12) {
        int index=0;
        for (int i=0; i<[self.dataSourceArray count]; i++) {
            UIColor *color = [allColorArray objectAtIndex:index];
            [colorArray addObject:color];
            index += 1;
            index = index%12;
            
            PieChartItem *item = [[self.dataSourceArray objectAtIndex:i] objectForKey:kRowItemKey];
            item.color = color;
        }
    }
    else {
        
    }
    
    chartView.titleArr =titleArray;
    chartView.valueArr =valueArray;
    chartView.colorArr =colorArray;
    [chartView setNeedsDisplay];
    
    [self.view insertSubview:chartView atIndex:0];
}

-(void)titleAction {
    
    if (dateSelectView.isHidden) {
        [titleButton setImage:[UIImage imageNamed:@"group_button_up.png"] forState:UIControlStateNormal];
        CGRect appRect = [[UIScreen mainScreen] applicationFrame];
        [UIView beginAnimations:nil context:nil];
        dateSelectView.frame =CGRectMake(0, appRect.size.height -250-44, appRect.size.width, 250);
        dateSelectView.hidden=NO;
        [UIView commitAnimations];   
    }
    else {
        [titleButton setImage:[UIImage imageNamed:@"group_button_down.png"] forState:UIControlStateNormal];
        CGRect appRect = [[UIScreen mainScreen] applicationFrame];
        [UIView setAnimationDuration:2];
        [UIView beginAnimations:nil context:nil];
        dateSelectView.frame = CGRectMake(0, appRect.size.height, appRect.size.width, 250);
        dateSelectView.hidden=YES;
        [UIView commitAnimations]; 
    }
}

-(IBAction)cancelAction
{
    [titleButton setImage:[UIImage imageNamed:@"group_button_down.png"] forState:UIControlStateNormal];
    CGRect appRect = [[UIScreen mainScreen] applicationFrame];
    [UIView setAnimationDuration:2];
    [UIView beginAnimations:nil context:nil];
    dateSelectView.frame = CGRectMake(0, appRect.size.height, appRect.size.width, 250);
    dateSelectView.hidden=YES;
    [UIView commitAnimations]; 
}

-(IBAction)doneAction
{
    [titleButton setImage:[UIImage imageNamed:@"group_button_down.png"] forState:UIControlStateNormal];
    CGRect appRect = [[UIScreen mainScreen] applicationFrame];
    [UIView setAnimationDuration:2];
    [UIView beginAnimations:nil context:nil];
    dateSelectView.frame = CGRectMake(0, appRect.size.height, appRect.size.width, 250);
    dateSelectView.hidden=YES;
    [UIView commitAnimations]; 
    
    NSMutableArray *startYearArray= [pikcerDataSource objectAtIndex:0];
    searchStartDate.year = [[startYearArray objectAtIndex:[startPickerView selectedRowInComponent:0]] intValue];
    NSMutableArray *startMonthArray= [pikcerDataSource objectAtIndex:1];
    searchStartDate.month = [[startMonthArray objectAtIndex:[startPickerView selectedRowInComponent:1]] intValue];
    NSMutableArray *startDayArray= [pikcerDataSource objectAtIndex:2];
    searchStartDate.day = [[startDayArray objectAtIndex:[startPickerView selectedRowInComponent:2]] intValue];
    
    NSMutableArray *endYearArray= [pikcerDataSource objectAtIndex:0];
    searchEndDate.year = [[endYearArray objectAtIndex:[endPickerView selectedRowInComponent:0]] intValue];
    NSMutableArray *endMonthArray= [pikcerDataSource objectAtIndex:1];
    searchEndDate.month = [[endMonthArray objectAtIndex:[endPickerView selectedRowInComponent:1]] intValue]; 
    NSMutableArray *endDayArray= [pikcerDataSource objectAtIndex:2];
    searchEndDate.day = [[endDayArray objectAtIndex:[endPickerView selectedRowInComponent:2]] intValue]; 
    
    NSString *titleString =[NSString stringWithFormat:@" %02d/%02d/%02d-%02d/%02d/%02d",
                            searchStartDate.year%100,
                            searchStartDate.month,
                            searchStartDate.day,
                            searchEndDate.year%100,
                            searchEndDate.month,
                            searchEndDate.day];
    [titleButton setTitle:titleString forState:UIControlStateNormal];
       
    [self getPieChartController];
    [self._tableView reloadData];
}

@end
